﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;
using YeaTrip.Framework.Log;

namespace YeaTrip.Framework.Filter
{
    public enum EventEnum
    {
        OnActionExecuting,
        OnActionExecuted,
        OnResultExecuting,
        OnResultExecuted,
        OnAuthorization,
    }
    /// <summary>
    /// Action日志属性(待定)
    /// </summary>
    public class ActionLogAttribute : ActionFilterAttribute
    {
        public bool LogOnResultExecuted { get; set; }
        public bool LogOnResultExecuting { get; set; }
        public bool LogOnActionExecuted { get; set; }
        public bool LogOnActionExecuting { get; set; }

        /// <summary>
        /// 默认只记录OnActionExecuting和OnResultExecuted
        /// </summary>
        public ActionLogAttribute()
        {
            LogOnActionExecuting = true;
            LogOnActionExecuted = false;
            LogOnResultExecuting = false;
            LogOnResultExecuted = true;
        }

        #region　IResultFilter　成员

        public override void OnResultExecuted(ResultExecutedContext filterContext)
        {
            if (LogOnResultExecuted)
            {
                //YeaTripLog.WriteLog(EventEnum.OnResultExecuted, filterContext);
            }
        }

        public override void OnResultExecuting(ResultExecutingContext filterContext)
        {
            if (LogOnResultExecuting)
            {
                //YeaTripLog.WriteLog(EventEnum.OnResultExecuting, filterContext);
            }
        }

        #endregion

        #region　IActionFilter　成员

        public override void OnActionExecuted(ActionExecutedContext filterContext)
        {
            if (LogOnActionExecuted)
            {
                //YeaTripLog.WriteLog(EventEnum.OnActionExecuted, filterContext);
            }
        }

        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            if (LogOnActionExecuting)
            {
                //YeaTripLog.WriteLog(EventEnum.OnActionExecuting, filterContext);
            }
        }

        #endregion
    }
}
